package com.gubei.oss.entity;

import lombok.Data;

@Data
public class Result<T> {

    private Boolean success;

    private String msg;

    private Integer code;

    private T data;


    public static Result ok() {
        Result result = new Result();
        result.setSuccess(Boolean.TRUE);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMsg(ResultCodeEnum.SUCCESS.getDesc());
        return result;
    }

    public static Result fail() {
        Result result = new Result();
        result.setSuccess(Boolean.FALSE);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMsg(ResultCodeEnum.FAIL.getDesc());
        return result;
    }

    public static <T> Result ok(T data) {
        Result result = new Result();
        result.setSuccess(Boolean.TRUE);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMsg(ResultCodeEnum.SUCCESS.getDesc());
        result.setData(data);
        return result;
    }

    public static <T> Result fail(T data) {
        Result result = new Result();
        result.setSuccess(Boolean.FALSE);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMsg(ResultCodeEnum.FAIL.getDesc());
        result.setData(data);
        return result;
    }


}
